<!-- 全局导航 -->
<template>
  <div class="root__nav">
    <div
      v-for="nav in navList"
      :key="nav.name"
      :class="[
        'nav__item',
        {'active': nav.path === currentPath}
      ]"
      @click="skip(nav)"
    >
      {{nav.meta.title}}
    </div>
  </div>
</template>

<script>
  export default {
    name: 'RootNav',
    computed: {
      currentPath() {
        return this.$route.path
      },
      navList() {
        return this.$router.options.routes
      }
    },
    methods: {
      skip(nav) {
        if (nav.path !== this.$route.path) {
        this.$router.push(nav.path)
      }
      }
    }
  }
</script>

<style scoped>
.root__nav {
  width: 200px;
  height: 100%;
  overflow: auto;
  box-sizing: border-box;
  border-right: 1px solid #dedede;
}

.nav__item {
  box-sizing: border-box;
  padding: 4px 10px 4px 20px;
  cursor: pointer;
  position: relative;
}

.nav__item:hover {
  box-shadow: 0 0 10px rgba(0, 0, 0, .1) inset;
}

.nav__item.active::before {
  display: block;
  content: '';
  width: 4px;
  height: 70%;
  background-image: linear-gradient(0deg, #ffafbd 0%, #ffc3a0 100%);
  left: 10px;
  top: 15%;
  position: absolute;
  border-radius: 20px;
}
</style>